﻿using System.Collections.Generic;
using System.IO;

namespace QunFaExpert
{
    public class Accounts
    {
        /// <summary>
        /// 从文件读取微博账号,密码,用户名和密码之间用空格或者逗号分开，每个账号一行
        /// ----------
        /// 用户名 密码
        /// username password
        /// ----------
        /// </summary>
        /// <param name="filename">导入账号的文件名</param>
        /// <returns></returns>
        public static List<Account> ReadAccounts(string filename = "accounts.txt")
        {
            List<Account> result = new List<Account>();
            using (var fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read))
            {
                using (var streamReader = new StreamReader(fileStream))
                {
                    streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
                    string strLine = streamReader.ReadLine();
                    while (strLine != null)
                    {
                        System.Diagnostics.Debug.WriteLine("adding " + strLine);
                        char[] separator = { ' ', ',' };
                        var account = strLine.Split(separator);
                        System.Diagnostics.Debug.WriteLine(string.Format("账号 {0}", account[0]));
                        result.Add(new Account(account[0], account[1]));
                        strLine = streamReader.ReadLine();
                    }
                }
            }
            return result;
        }
    }
    public class Account
    {
        public string username;
        public string pwd;

        public Account(string u, string p)
        {
            this.username = u;
            this.pwd = p;
        }
    }
}
